<template>
	<view class="list-block">
		<view class="item" v-for="(item,index) in list" :key="100 + item.id">
			<view class="content">
				<view class="block-avator">
					<image :src="item.wxuser.avatar_text ? item.wxuser.avatar_text : '/static/user.png'" mode="widthFix"></image>
				</view>
				<view class="block-content">
					<view class="block-content__name">{{item.wxuser.nickname}} <text
							class="block-content__type" v-if="item.label.name">{{item.label.name}}</text></view>
					<view class="block-content__time" @click="toHomeDetail(item)">{{item.title}}</view>
				<!-- 	<view class="block-content__desc" @click="toHomeDetail(item)">
						{{item.content|handleNtoBrSplice}}<text class="red">[全文]</text>
					</view> -->
					<view class="block-content__images" v-if="item.images.length > 0">
						<view class="block-content__images-image" v-for="(img, i) in item.images" :key="i">
							<image :src="handler(img)" mode="widthFix" @tap="previewOpen($event, item.images)"
								:data-src="img"></image>
						</view>

					</view>

					<view class="block-content__more" @click="toHomeDetail(item)">
						<uni-icons color="#e6e6e6" type="eye"></uni-icons><text
							class="block-content__more-txt">详情</text>
					</view>
				</view>
			</view>

			<!--
			<view class="zu" @click="toHomeDetail(item)">
				<view class="zu-item">
					<uni-icons :color="item.likenum>0 ? '#f07373' : '#1a1a1a'" :type="item.likenum>0 ? 'star-filled' : 'star'"></uni-icons>
					
					<text>{{item.likenum > 0 ? item.likenum : '收藏'}}</text>
				</view>
				<view class="zu-item">
					<uni-icons color="#1a1a1a" type="compose"></uni-icons>
					<text>{{item.comment_num ? item.comment_num : '评论'}}</text>
				</view>
				<view class="zu-item">
					<uni-icons :color="item.is_zan ? '#f07373' : '#1a1a1a'" type="hand-thumbsup" :type="item.is_zan ? 'hand-thumbsup-filled' : 'hand-thumbsup'"></uni-icons>
					<text>{{item.zannum ? item.zannum :  '点赞'}}</text>
				</view>
			</view>
-->

			<view class="fot">
				<text>{{item.createtime}}，{{item.viewcount}}人浏览</text>
			</view>

		</view>

		<previewImage ref="previewImage" :opacity="0.8" :circular="true" @longPress="longPress"></previewImage>

	</view>
</template>

<script>
	import previewImage from '@/components/kxj-previewImage/kxj-previewImage.vue'
	import {
		handleNtoBrSplice
	} from '@/utils/index.js'
	export default {
		components: {
			previewImage
		},
		props: {
			list: {
				type: Array,
				default () {
					return []
				}
			}
		},
		data() {
			return {

			};
		},
		filters: {
			handleNtoBrSplice(time) {
				return handleNtoBrSplice(time)
			}
		},
		methods: {
			previewOpen(e, imgsarr) {
				var param = e.currentTarget.dataset.src

				// imgsarr.forEach(function(value, index, array) {
				// 	if (value.indexOf("static") != -1) {
				// 		imgsarr[index] = value + '-web';
				// 	}
				// })

				// if (param.indexOf("static") != -1) {
				// 	param = param + '-web'
				// }

				this.$refs.previewImage.open(param, imgsarr)
			},
			//长按图片
			longPress(data) {

			},
			handler(img) {
				if(img.indexOf("static.dadi30.com") != -1){
					return img + '-sl100';
				}else{
					return img;
				}
			},
			//打开文章
			toHomeDetail(item) {
				const params = {
					id: item.id,
					title: item.title,
					create_time: item.createtime,
					wxuser: item.wxuser.nickname,
					zancount: item.zancount,
					viewcount: item.viewcount
				}

				// 跳转到文章页
				// uni.navigateTo({
				// 	url: '/pages/home-detail/home-detail?params=' + JSON.stringify(params)
				// })
				
				uni.navigateTo({
					url: '/pages/home-detail/home-detail?id=' + item.id
				})

			}
		}
	}
</script>

<style lang="scss">
	.mescroll-body {
		padding-bottom: 120rpx;
	}

	.item {
		padding-top: 10px;
		border-bottom: 1px solid #eee;
	}

	.content {
		display: flex;
		justify-content: space-between;
		padding: 10px;

		.block-avator {
			width: 40px;
			font-size: 0;
			overflow: hidden;

			image {
				width: 100%;
				border-radius: 5px;
			}
		}

		.block-content {
			flex: 1;
			font-size: 15px;
			margin-left: 10px;
			position: relative;
			overflow: hidden;

			.block-content__type {
				font-size: 12px;
				border: 1px solid red;
				margin-left: 10px;
				padding: 1px 6px;
				color: red;
				border-radius: 4px;
			}

			.block-content__images {
				display: flex;
				flex-wrap: wrap;
				margin-top: 5px;
				overflow: hidden;

				.block-content__images-image {
					width: 80px;
					font-size: 0;
					margin-right: 2px;
					margin-top: 2px;
					font-size: 0;
					position: relative;

					image {
						width: 80px;
						height: auto;
					}

					.block-content__images-image-more {
						position: absolute;
						top: 0;
						left: 0;
						right: 0;
						bottom: 0;
						background: rgba(0, 0, 0, .3);
						z-index: 2;
						color: #fff;
						font-size: 14px;
						display: flex;
						justify-content: center;
						padding: 24%;
						text-align: center;
						line-height: 1.6;
					}
				}
			}

			.block-content__name {
				color: #000;
			}

			.block-content__time {
				color: rgb(44, 62, 80);
				font-size: 12px;
				margin-top: 5px;
			}

			.block-content__desc {
				color: rgb(44, 62, 80);
				margin-top: 5px;
				overflow: hidden;

			}

			.block-content__more {
				position: absolute;
				top: 0;
				right: 0;
				color: #2f3f52;
				font-size: 12px;
				display: flex;
				align-items: center;

				.block-content__more-txt {
					margin-left: 4px;
				}
			}
		}
	}

	.zu {
		display: flex;
		justify-content: space-between;
		font-size: 12px;
		padding: 10px 0;

		.zu-item {
			flex: 1;
			text-align: center;
			display: flex;
			align-items: center;
			justify-content: center;
			box-sizing: border-box;

			&:nth-child(2) {
				border-left: 1px solid #eee;
				border-right: 1px solid #eee;
			}

			text {
				margin-left: 4px;
			}
		}
	}

	.fot {
		padding: 10px 0 10px 60px;
		font-size: 12px;
		color: gray;
	}

	image {
		width: 100%;
		height: 100%;
	}
</style>
